'use strict';
const dayjs = require("dayjs");
module.exports = app => {
  const { STRING, INTEGER, TINYINT } = app.Sequelize;
    return app.model.define(
      'alarmRule',
      {
          id: {type: INTEGER, primaryKey: true, autoIncrement: true},
          company: INTEGER,
          category: STRING(50),
          threshold: STRING(50),
          unit: STRING(50),
          is_deleted: TINYINT(1),
          description: STRING(255),
          // 启用状态
          status: TINYINT(1),
          created_time: {
                type: app.Sequelize.DATE,
                allowNull: false,
                get() {
                    return dayjs(this.getDataValue('created_time')).format('YYYY-MM-DD HH:mm:ss');
                }
          },
          updated_time: {
              type: app.Sequelize.DATE,
              allowNull: false,
              get() {
                  return dayjs(this.getDataValue('updated_time')).format('YYYY-MM-DD HH:mm:ss');
              }
          },
      },
      {
          tableName: 'alarm_rule',
          timestamps: true, // 启用时间戳(createdAt, updatedAt)
          updatedAt: 'updated_time', // 不想要 updatedAt
          createdAt: 'created_time', // 想要  createdAt 但是希望名称叫做 created_at
      }
  );
};
